const mongoose = require('mongoose')

const Schema = mongoose.Schema

const imageSchema = new mongoose.Schema({
    title: {
        type: String , 
        maxlength: 128,
        required: true, 
        minlength: 3
    },
    uploader_id: {
        type: Schema.Types.ObjectId,
        required: true
    },
    description: {
        type: String,
        required: true,
        maxlength: 1024 
    },
    originalname: {
        type: String,
        required: true,
        maxlength: 128
    },
    mimetype: {
        type: String,
        enum: ['image/jpeg', 'image/png', 'image/jpg'],
        required: true
    },
    diskfilename: {
        type: String,
        required: true
    },
    likes: {
        type: Number,
        required: true,
        default: 0
    },
    visit: {
        type: Number,
        required: true,
        default: 0
    }
}, {timestamps: true})

mongoose.model('Image', imageSchema, 'image')